export function adapterIn(userData) {
    if (userData.step == null && userData.order == null) {
        return userData;
    }

    const inJson = {
        nodes: [], edges: []
    }
    if (userData.step) {
        userData.step.forEach(v => {
            let node = {
                id: v.gui?.id,
                x: parseInt(v.gui?.xloc || 0),
                y: parseInt(v.gui?.yloc || 0),
                type: v.gui.type || v.type,
                text: {
                    x: parseInt(v.gui?.text?.x || 0), y: parseInt(v.gui?.text?.y || 0), value: v.gui?.text?.value
                },
                properties: {}
            };
            // var strings = Object.keys(v);
            for (const s in v) {
                if (s == "name" || s == "attributes" || s == "cluster_schema" || s == "custom_distribution" || s == "description" || s == "partitioning" || s == "remotesteps" || s == "type" || s == "distribute" || s == "copies" || s == "dynamicInputFlag" || s == "GUI" || s == "gui") {
                    continue;
                }
                // console.log(s)
                // console.log(v[0])
                node.properties[s] = v[s];
            }
            inJson.nodes.push(node);
        })
    }

    if (userData.order && userData.order.hop) {
        userData.order.hop.forEach(v => {
            let edge = {
                id: v.id,
                //  endPoint: 0,
                //  pointsList: [0,0],
                sourceNodeId: v.from,
                targetNodeId: v.to,
                type: "SquareLakePolylineEdge",
                // properties: {}
            };
            if (v.gui && v.gui.text) {

                edge.text = {
                    value: v.gui?.text?.value,
                    x: parseInt(v.gui?.text?.x),
                    y: parseInt(v.gui?.text?.y)
                }
            }
            for (const s in v) {
                if (s == "GUI" || s == "gui" || s == "from" || s == "to" || s == "id" || s == "enabled") {
                    continue;
                }
                edge.properties[s] = v[s];
            }

            inJson.edges.push(edge);
        })
        //  console.log(inJson.edges)
    }
    // console.log(JSON.stringify(inJson))
    return inJson;
}